*This file creates later trade table A.5

*Import deflated Comtrade data assigned to Finnish industry classifications.
* Use until 1970 (end of study period)
use  "$path/comtrade_data_isic_fin_def.dta" , clear
keep if year<1971
collapse (sum) trade_ussr trade_row, by(isic)
gen twodigt=substr(isic, 1,2)

*Import reparations shocks
preserve
use "$path/industry_data.dta", clear
keep if year==1943
tostring isic, replace
tempfile repa
save `repa'
restore

joinby isic using `repa', unmatched(master)

*Create treade measures
gen ln_ussr=ln(trade_ussr)
gen ln_trade_row=ln(trade_row)
gen trade_ussr_m=trade_ussr/1000000
gen trade_row_m=trade_row/1000000

global controls43 power_labor_share1943 ln_value_prod1943 lnlabor_all1943 ln_relative_wage1943 ln_establishments1943 skilled1943 ln_inputs_all1943 ln_valueadded1943 

*Import industry skill. See paper for details.
preserve
use "$path/ind_edu.dta", clear
tempfile education
gen low_edu=(high_edu!=1)
save `education' 
restore

drop _merge
joinby digt2 using `education' , unmatched (master) 

preserve
keep if year==1943
replace high_edu=0 if high_edu==.&repa_sharel==0
replace low_edu=. if high_edu==.
gen h_std=repa_sharel*high_edu
egen h_std2=std(repa_sharel*high_edu)
gen l_std=repa_sharel*low_edu
egen l_std2=std(l_std)
keep isic h_std2 l_std2 low_edu high_edu
tempfile education2
save `education2' 
restore

drop _merge
joinby isic using `education2' , unmatched (master) 


*Estimations

reg ln_ussr treat_std_l $controls43 if year==1943, r
estadd local c1943 "\checkmark"
estadd local established "Yes"

sum ln_ussr
estadd scala ymean=r(mean)
estimates store e1

reg ln_trade_row treat_std_l $controls43 if year==1943, r
estadd local c1943 "\checkmark"
estadd local established "Yes"

sum ln_trade_row
estadd scala ymean=r(mean)
estimates store e2 

reg ln_ussr h_std2 l_std2 $controls43 if year==1943, r
estadd local c1943 "\checkmark"
estadd local established "Yes"

sum ln_ussr
estadd scala ymean=r(mean)
estimates store e3

reg ln_trade_row h_std2 l_std2 $controls43 if year==1943, r
estadd local c1943 "\checkmark"
estadd local established "Yes"

sum ln_trade_row
estadd scala ymean=r(mean)
estimates store e4 

reg ln_ussr treat_std_l $controls43 if year==1943&timberpaper==0, r
estadd local c1943 "\checkmark"
estadd local established "No"

sum ln_ussr
estadd scala ymean=r(mean)
estimates store e5

reg ln_trade_row treat_std_l $controls43 if year==1943&timberpaper==0, r
estadd local c1943 "\checkmark"
estadd local established "No"

sum ln_trade_row
estadd scala ymean=r(mean)

estimates store e6

gen sovietshare=trade_ussr/(trade_row+trade_ussr)

gen treatq=(repa_sharel>0)
gen high_edu_treat=((high_edu==1)*(repa_sharel>0))
gen low_edu_treat=((low_edu==1)*(repa_sharel>0))

*Calculate share of Soviet trade by exposure
*These share values inputted into the table

sum sovietshare if treatq==1
sum sovietshare if high_edu_treat==1
sum sovietshare if low_edu_treat==1

sum sovietshare if treatq==1&timberpaper==0
sum sovietshare if high_edu_treat==1&timberpaper==0
sum sovietshare if low_edu_treat==1&timberpaper==0


label var  treat_std_l "Reparations share"
label var  h_std2  "HS x Reparations share"
label var  l_std2 "LS x Reparations share"


esttab e1 e5 e3 e2 e6 e4  ///
using   "$tables/trade_table.tex",  ///
mgroups("ln Soviet exports" "ln ROW exports"  ,   pattern(1 0 0  1 0 0)   prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) ) ///
replace  keep(treat_std_l h_std2 l_std2) nonotes ///
b(%9.3f) se(%9.3f) stats(N ymean established, fmt(0 3) layout(@ @ @) ///
labels("N" "Y mean" "Established"    ///
)) ///
label star(* .1 ** .05 *** .01) nodepvars nomtitle 


